package com.yangye.otherdemo.countdownlatchdemo;

import java.util.concurrent.CountDownLatch;

/**
 * Created by yangye on 2019/7/3
 */
public class CountDownLatchDemo {

	public static void main(String[] args) throws InterruptedException {
		for (int i = 0; i < 100; i++) {
			CountDownLatch cdl = new CountDownLatch(4);
			Thread player1 = new Thread(() -> {
				System.out.println("玩家1已入场");
				cdl.countDown();
			});
			Thread player2 = new Thread(() -> {
				System.out.println("玩家2已入场");
//				cdl.countDown();

			});
			Thread player3 = new Thread(() -> {
				System.out.println("玩家3已入场");
//				cdl.countDown();
			});
			Thread player4 = new Thread(() -> {
				System.out.println("玩家4已入场");
//				cdl.countDown();
			});
			player1.start();
			player2.start();
			player3.start();
			player4.start();

			try {
				cdl.await();
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
			System.out.println("人已满，开始发牌");
		}
	}
}
